package com.fuluwa.domain.order.service;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import com.fuluwa.domain.order.model.Order;
import com.fuluwa.domain.order.model.OrderFactory;
import com.fuluwa.domain.order.model.OrderItem;
import com.fuluwa.domain.order.model.PayType;
import com.fuluwa.domain.order.repository.OrderRepository;
import com.fuluwa.infra.exception.PersistenceException;

public class OrderServiceImpl implements OrderService {
	@Autowired
	OrderRepository orderRepository;

	@Override
	public Order createNewOrder(String seller, String remark, PayType payType, Set<OrderItem> items)
			throws PersistenceException {
		return OrderFactory.createNewOrder(seller, remark, payType, items);
	}

	@Override
	public void payment(String orderNo) throws PersistenceException {
		Order order = orderRepository.findByNumber(orderNo);
		order.payment();
	}

	@Override
	public void confirm(String orderNo) throws PersistenceException {
		Order order = orderRepository.findByNumber(orderNo);
		order.confirm();
	}

	@Override
	public void complete(String orderNo) throws PersistenceException {
		Order order = orderRepository.findByNumber(orderNo);
		order.complete();
	}

	@Override
	public void cancel(String orderNo) throws PersistenceException {
		Order order = orderRepository.findByNumber(orderNo);
		order.cancel();
	}

}
